/*
 * @Author: new-wang
 * @Date: 2025-08-20 18:02:07
 * @LastEditors: new-wang
 * @LastEditTime: 2025-08-28 09:57:23
 * @FilePath: \nest-demo\src\module\main\main.controller.ts
 * @Description:
 */
import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
} from '@nestjs/common'
import { ApiTags, ApiOperation, ApiBody, ApiBearerAuth } from '@nestjs/swagger'
import { MainService } from './main.service'
import { CreateMainDto } from './dto/create-main.dto'
import { UpdateMainDto } from './dto/update-main.dto'
import { LoginDto, RegisterDto } from '../system/auth/dto'
import {
  ClientInfo,
  ClientInfoDto,
} from 'src/common/decorators/clientInfo.decorator'

@ApiTags('根目录')
@Controller('/')
export class MainController {
  constructor(private readonly mainService: MainService) {}

  @ApiOperation({
    summary: '用户注册',
  })
  @ApiBody({
    type: RegisterDto,
    required: true,
    description: '用户注册信息',
  })
  @Post('register')
  register(@Body() user: RegisterDto) {
    return this.mainService.register(user)
  }

  @ApiOperation({
    summary: '用户登录',
  })
  @ApiBody({
    type: LoginDto,
    required: true,
    description: '用户登录信息',
  })
  @Post('login')
  login(@Body() user: LoginDto, @ClientInfo() clientInfo: ClientInfoDto) {
    return this.mainService.login(user, clientInfo)
  }

  // 2025年8月27日08:46:28

  @Post()
  create(@Body() createMainDto: CreateMainDto) {
    return this.mainService.create(createMainDto)
  }

  @Get()
  findAll() {
    return this.mainService.findAll()
  }

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.mainService.findOne(+id)
  }

  @Patch(':id')
  update(@Param('id') id: string, @Body() updateMainDto: UpdateMainDto) {
    return this.mainService.update(+id, updateMainDto)
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.mainService.remove(+id)
  }
}
